#include "C_SpaceSprite.h"


C_SpaceSprite::C_SpaceSprite()
{
	m_lightSprite = new C_Sprite();
	m_lightSprite->loadFromFile("data/textures/52.png");
	m_lightSprite->setColor(255, 100, 0, 255);

	m_backSprite = new C_Sprite();
	m_backSprite->loadFromFile("data/textures/stars/star_light.png");
	m_backSprite->setColor(255, 100, 0, 255);
	m_cellSize = NULL;
}


C_SpaceSprite::~C_SpaceSprite()
{
}

void C_SpaceSprite::render()
{
	if (m_cellSize == NULL) return;

	float x = (*m_cellSize / 150)*m_spaceSize.x;
	float y = (*m_cellSize / 150)*m_spaceSize.y;
	this->setSize(x, y);

	if (*m_cellSize > 300.0f)
	{
		if (*m_cellSize < 400.0f)
		{
			this->setColor(
				this->red(),
				this->green(),
				this->blue(),
				255.0f / 100.0f*(*m_cellSize - 300.0f)
				);
		}
		C_Sprite::render();

		float nx = x*1.8f;
		float ny = y*1.8f;
		m_backSprite->setSize(nx, ny);
		if (*m_cellSize < 400.0f)
		{
			m_backSprite->setColor(
				m_backSprite->red(),
				m_backSprite->green(),
				m_backSprite->blue(),
				255.0f/100.0f*(*m_cellSize - 300.0f)
			);
		}
		else m_backSprite->setColor(m_backSprite->red(), m_backSprite->green(), m_backSprite->blue(), 255);
		m_backSprite->setPos(this->pos().x - (nx / 2.0f - x / 2.0f), this->pos().y - (ny / 2.0f - y / 2.0f));
		m_backSprite->render();
	}

	if (*m_cellSize < 400.0f)
	{
		float nx = x * 3;
		float ny = y * 3;
		m_lightSprite->setSize(nx, ny);
		if (*m_cellSize > 300.0f)
		{
			m_lightSprite->setColor(
				m_lightSprite->red(),
				m_lightSprite->green(),
				m_lightSprite->blue(),
				255.0f / 100.0f*(400.0f - *m_cellSize)
				);
		}
		else m_lightSprite->setColor(m_lightSprite->red(), m_lightSprite->green(), m_lightSprite->blue(), 255);
		m_lightSprite->setPos(this->pos().x - (nx / 2.0f - x / 2.0f), this->pos().y - (ny / 2.0f - y / 2.0f));
		m_lightSprite->render();
	}
}
